package com.unicomcz.mobile;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.unicomcz.ActionBase;

public class MobileInAction extends ActionBase {
    private List<MobTypeBean> mobTypes;
    private String mobType;
    private int amount;
    
	
	public String getMobType() {
		return mobType;
	}
	public void setMobType(String mobType) {
		this.mobType = mobType;
	}
	public int getAmount() {
		return amount;
	}
	public void setAmount(int amount) {
		this.amount = amount;
	}
	public List<MobTypeBean> getMobTypes() {
		return mobTypes;
	}
	public void setMobTypes(List<MobTypeBean> mobTypes) {
		this.mobTypes = mobTypes;
	}
	public MobileInAction(){
		log = Logger.getLogger(this.getClass());
	}
	
	public String executeAction(){
		mobTypes  = new ArrayList<MobTypeBean>();
		String str = "select terminal_model_code,terminal_model_name from dls_code_terminal";
		boolean flag = query("dls",mobTypes,str);
		if (!flag){
			return "fail";
		}
		if (amount<=0){
			addActionMessage("入库失败!数量必须大于0");
            return SUCCESS;
		}
		boolean dbFlag = setupConn("dls");
		if (!dbFlag) {
            log.debug(userInfo.getUserId()+"登陆系统失败!因为建立数据库连接失败");
            addActionMessage("修改密码失败!因为建立数据库连接失败");
            return INPUT;
        }
		int rtv = execProc("{call mob_in(?,?,?,?)}",4);
	    if (rtv == 0) {
	           addActionMessage("入库成功！");
	           amount=0;
	    }else if (rtv == -1){
	           addActionMessage("入库失败！");
	    }
	    tearDown();    
		return SUCCESS;
    }
	@Override
	protected void rs2List(ResultSet rs, List out) throws Exception {
		// TODO Auto-generated method stub
		MobTypeBean mb = new MobTypeBean();
		mb.setModelCode(rs.getString(1));
		mb.setModelName(rs.getString(2));
		out.add(mb);
	}
	
	protected void regProcParam() {
        try {
            //og.debug(mobile);
           //cstmt.setString(1, mobile);
           cstmt.setString(1,userInfo.getDepartCode());
           cstmt.setString(2,mobType);
           cstmt.setInt(3, amount);
        }catch(Exception e) {
            
        }
        
    }

}
